package com.start.workflow.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.start.common.api.Result;
import com.start.common.dataRule.DataQueryConstructor;
import com.start.core.annotations.RegisterPermission;
import com.start.workflow.core.service.StartActCategoryService;
import com.start.workflow.entity.StartActCategory;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/start/actCategory")
@Tag(name = "流程类别管理")
public class StartActCategoryController {
    @Autowired
    private StartActCategoryService startActModelManage;

    @GetMapping("/page")
    @PreAuthorize("@pas.hasPermission('start:act:model:category:info')")
    @RegisterPermission(value = "start:act:model:category:info", name = "查询流程类别")
    public Result<?> page(Page<StartActCategory> page) {
        QueryWrapper<StartActCategory> queryWrapper = DataQueryConstructor.createEntity(StartActCategory.class);
        return Result.ok(startActModelManage.page(page, queryWrapper));
    }

    @Operation(summary = "添加流程类别")
    @PostMapping("/add")
    @PreAuthorize("@pas.hasPermission('start:act:model:category:add')")
    @RegisterPermission(value = "start:act:model:category:add", name = "添加流程类别")
    public Result<?> save(@RequestBody StartActCategory modelVo) {
        startActModelManage.save(modelVo);
        return Result.ok();
    }

    @Operation(summary = "获取类别配置详情")
    @PreAuthorize("@pas.hasPermission('start:act:model:category:info')")
    @RegisterPermission(value = "start:act:model:category:info", name = "查询流程类别")
    @GetMapping("/getActModelConfigDetail/{modeId}")
    public Result<?> getActModelConfigDetail(@PathVariable("modeId") String modeId) {
        return Result.ok(startActModelManage.getById(modeId));
    }

    @Operation(summary = "修改类别")
    @PutMapping("/updateById")
    @PreAuthorize("@pas.hasPermission('start:act:model:category:update')")
    @RegisterPermission(value = "start:act:model:category:update", name = "查询流程类别")
    public Result<?> updateById(@RequestBody StartActCategory entity) {
        startActModelManage.updateById(entity);
        return Result.ok();
    }

    @Operation(summary = "删除类别")
    @DeleteMapping("/deleteById/{id}")
    @PreAuthorize("@pas.hasPermission('start:act:model:category:delete')")
    @RegisterPermission(value = "start:act:model:category:delete", name = "删除流程类别")
    public Result<?> deleteById(@PathVariable("id") String id) {
        startActModelManage.removeById(id);
        return Result.ok();
    }

}
